<?php
class Util
{
	//防止类被初始化
	private function __construct(){}
	
	//cookies操作
	public static function setCookies($key, $value)
	{
		$value = serialize($value);
		setcookie($key, $value, time() + COOKIE_EXPIRE, '/');
	}
	
	public static function getCookies($key)
	{
		if (isset($_COOKIE[$key])){
			return unserialize($_COOKIE[$key]); 
		}
		return false;
	}
	
	public static function clearCookies($key)
	{
		setcookie($key, '', time()-1, '/');
		return true;
	}
	
	//页面跳转
	public static function redirect($url = 'www.weibo.com')
	{
		@header("HTTP/1.1 302 Moved Temporarily");
		@header("Status: 302 Moved Temporarily");
		@header("location: " . $url);
		exit();
	}
	
	//传回ajax值
	public static function ajaxReturn($status, $msg=array())
	{
		$return['status'] = $status;
		$return['msg'] = $msg;
		echo json_encode($return);
		exit();
	}
	
	//错误信息记录
	public static function log($log)
	{
		sae_debug($log);
		return ;
	}
	
	//返回smarty引擎
	public static function getTpl($app='Index')
	{
		$tpl = new Smarty();
		$tpl->template_dir = ROOT_DIR . 'Templates/' . $app;
		$tpl->cache_dir = TMP_PATH;
		$tpl->config_dir = TMP_PATH;
		$tpl->compile_dir = TMP_PATH;
		$tpl->left_delimiter = '<{';
		$tpl->right_delimiter = '}>';
		return $tpl;
	}
}